package com.ruoyi.api.web;

import com.ruoyi.api.base.BaseApi;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.weixin.domain.Address;
import com.ruoyi.weixin.service.IAddressService;
import com.ruoyi.weixin.service.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/address")
public class AddressApi extends BaseApi {

    @Autowired
    private IAddressService addressService;

    @Autowired
    private IClientService clientService;


    @PostMapping("/addAddress")
    public AjaxResult addAddress(Address address){
        addressService.insertAddress(address);
        return success("添加成功", address);
    }

    @PostMapping("/editAddress")
    public AjaxResult editAddress(Address address){
        addressService.updateAddress(address);
        return success("修改成功", address);
    }

    @PostMapping("/addressDefault")
    public AjaxResult addressDefault(String clientId, String addressId){
        addressService.addressDefault(clientId, addressId);
        return success("设置成功");
    }

    @PostMapping("/getAddress")
    public AjaxResult getAddress(String clientId){
        List<Address> address = addressService.selectAddressByClientId(clientId);
        return success("获取成功", address);
    }

    @PostMapping("/deleteAddress")
    public AjaxResult deleteAddress(String addressId){
        addressService.deleteAddressById(addressId);
        return success("删除成功");
    }

    @PostMapping("/getAddressById")
    public AjaxResult getAddressById(String addressId){
        return success("获取成功", addressService.selectAddressById(addressId));
    }
}
